package byopenwrt

import (
	"bylib/bylog"
	"fmt"
	"github.com/vishvananda/netlink"
	"github.com/vishvananda/netlink/nl"
)
func GetGatewayByIf(ifname string)(gateway string,err error){
	link, err := netlink.LinkByName("eth0")
	if err!=nil{
		return "",err
	}
	routes, err :=netlink.RouteList(link,nl.FAMILY_V4)
	for _,r:=range routes{
		bylog.Debug("r=%+v",r)
		if r.Dst==nil && r.Gw!=nil{
			return r.Gw.String(),nil
		}
	}
	return "",fmt.Errorf("can not find")
}
